import { defineConfig,loadEnv } from 'vite'
import * as path from 'path';
import vue from '@vitejs/plugin-vue'
import autoprefixer from 'autoprefixer'; // 自动给C3样式添加厂商前缀
import cesium from 'vite-plugin-cesium'


export default ({ mode }) => {
  const env = loadEnv(mode, process.cwd());
  return defineConfig({
    base: env.VITE_BASE_URL,
    resolve: {
      // 设置别名
      alias: {
        '@': path.resolve(__dirname, 'src'),
      },
    },
    css: {
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
        },
      },
      postcss: {
        plugins: [
          autoprefixer({
            overrideBrowserslist: [
              'Android 4.1',
              'iOS 7.1',
              'Chrome > 31',
              'ff > 31',
              'ie >= 8',
            ],
          }),
        ],
      },
    },

    plugins: [
      vue(),
      cesium()
    
    ],
    build: {
      commonjsOptions: {
        // 默认内部只处理了node_modules，需要将"packages/"也标识处理
        include: /node_modules|packages/,
      },
    },
    server: {
      hmr: true,
      port: 3000,
      proxy: {
        '/wn-api': {
          target: 'http://192.168.104.205:50000', //正式
          // target: 'http://192.168.102.26:50000', // 测试
          changeOrigin: true,
        },
      },
    },
  });
};
